<?php
namespace app\service;
use alipay\AopClient;
use alipay\AlipayUserAgreementPageSignRequest;
class payService{
    const PRIKEYPATH = '/www/wwwroot/zaozao/prikey.txt';//私钥路径
    const PUBKEYPATH = '/www/wwwroot/zaozao/pubkey.txt';//支付宝公钥路径
   

    private $app_id;//支付宝分配给开发者的应用
    private $method;//接口名称
    private $format;//仅支持JSON  no
    private $charset = 'UTF-8';//请求使用的编码格式，如utf-8,gbk,gb2312等
    private $sign_type = 'RSA2';//商户生成签名字符串所使用的签名算法类型，目前支持RSA2和RSA，推荐使用RSA2
    private $sign;//商户请求参数的签名串  no
    private $timestamp;//发送请求的时间，格式"yyyy-MM-dd HH:mm:ss"
    private $version = '1.0';//调用的接口版本，固定为：1.0
    private $app_auth_token;//详见应用授权概述 no
    private $biz_content;//请求参数的集合，最大长度不限，除公共参数外所有请求参数都必须放在这个参数中传递，具体参照各产品快速接入文档
    
    //第三方应用
    public function getPublicContent(){
        $aop = new AopClient ();
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->appId = '2017071807800670';
        $aop->rsaPrivateKey = file_get_contents(self::PRIKEYPATH);//私钥路径
        $aop->alipayrsaPublicKey= file_get_contents(self::PUBKEYPATH);//支付宝公钥路径
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='UTF-8';
        $aop->format='json';
        return $aop;
    }
    
    public function agreement(){
        $aop = $this->getPublicContent();
        $request = new AlipayUserAgreementPageSignRequest ();
        $request->setBizContent("{" .
        "\"sign_validity_period\":\"2m\"," .
        "\"product_code\":\"INDUSTRY|LIFE_PAYMENT\"," .
        "\"external_logon_id\":\"18856151031\"," .
        "\"personal_product_code\":\"GENERAL_WITHHOLDING_P\"," .
        "\"sign_scene\":\"INDUSTRY|CARRENTAL\"," .
        "\"external_agreement_no\":\"test\"," .
        "\"third_party_type\":\"PARTNER\"," .
        "\"zm_auth_params\":{" .
        "\"buckle_app_id\":\"\"," .
        "\"buckle_merchant_id\":\"268820000000414397785\"" .
        " }," .
        "\"prod_params\":{" .
        "\"auth_biz_params\":\"{\\\"platform\\\":\\\"taobao\\\"}\"" .
        " }," .
        "\"promo_params\":\"{\\\"key\\\":\\\"value\\\"}\"," .
        "\"access_params\":{" .
        "\"channel\":\"QRCODEORSMS\"" .
        " }," .
        "\"sub_merchant\":{" .
        "\"sub_merchant_id\":\"2088331732150830\"," .
        "\"sub_merchant_name\":\"滴滴出行\"," .
        "\"sub_merchant_service_name\":\"滴滴出行免密支付\"," .
        "\"sub_merchant_service_description\":\"免密付车费，单次最高500\"" .
        " }," .
        "\"device_params\":{" .
        "\"device_id\":\"device12345\"," .
        "\"device_name\":\"电视\"," .
        "\"device_type\":\"TV\"" .
        " }," .
        "\"merchant_process_url\":\"https://www.merchantpage.com/index?processId=2345678\"," .
        "\"identity_params\":{" .
        "\"user_name\":\"张三\"," .
        "\"cert_no\":\"61102619921108888\"," .
        "\"identity_hash\":\"8D969EEF6ECAD3C29A3A629280E686CF0C3F5D5A86AFF3CA12020C923ADC6C92\"," .
        "\"sign_user_id\":\"2088202888530893\"" .
        " }," .
        "\"agreement_effect_type\":\"DIRECT\"," .
        "\"user_age_range\":\"{\\\"min\\\":\\\"18\\\",\\\"max\\\":\\\"30\\\"}\"," .
        "\"period_rule_params\":{" .
        "\"period_type\":\"DAY\"," .
        "\"period\":3," .
        "\"execute_time\":\"2019-01-23\"," .
        "\"single_amount\":10.99," .
        "\"total_amount\":600," .
        "\"total_payments\":12" .
        " }" .
        " }");
        $result = $aop->pageExecute ( $request);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        var_dump($result->$responseNode);die;
        $resultCode = $result->$responseNode->code;
        if(!empty($resultCode)&&$resultCode == 10000){
        echo "成功";
        } else {
        echo "失败";
        }
    }
   

    
}